// Initialize your app
var myApp = new Framework7({
    modalTitle: '提示',
    modalButtonOk: '确定',
    modalButtonCancel: '取消',
    // Hide and show indicator during ajax requests
    onAjaxStart: function (xhr) {
        myApp.showIndicator();
    },
    onAjaxComplete: function (xhr) {
        myApp.hideIndicator();
    },
    ignoreCache:['loginView.html'],
});

// Export selectors engine
var $$ = Dom7;

// Add view
var mainView = myApp.addView('.view-main', {
    // Because we use fixed-through navbar we can enable dynamic navbar
    dynamicNavbar: true,
    ignoreCache:['loginView.html'],
    //domCache:true,
});

//ylm------------------------------------------------------------------------
myApp.onPageInit('activateView', function (page) {
    $$('.navbar-inner').css('background-color','transparent');
    if($("#demo").length>0) {
        $$('.navbar-inner').css('background-color','#2E9DB4');
    }
});
//登入
myApp.onPageInit('loginView', function (page) {
    //ajax请求公司logo

    mainView.router.refreshPage();
    mainView.router.reloadPage("loginView.html");

    $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/getCompanyLogo', {session_id:localStorage.getItem("sessionid")}, function (data) {
        var obj = eval('(' + data + ')');
        if (obj.code === 1){
            $$(".companyLogo").attr("src", "imgs/3435355_03.png");
        }
        else {
            $$(".companyLogo").attr("src", obj.data);
        }
    });

    $$('.navbar-inner').css('background-color','transparent');
    if($("#demo").length>0) {
        $$('.navbar-inner').css('background-color','#2E9DB4');
    }
    // 点击登入按钮
    $$('.button.button-big.loginView-btn').on('click', function () {
        // 获取用户登入信息
        var tel = $$('.loginView-tel-text').val();
        var pwd = $$('.loginView-pwd-password').val();
        //判断输入信息是否为空
        if (tel === "") {
            myApp.alert('请输入手机号');
            return;
        }
        //验证手机号的合法性
        if (!(/^1[3|4|5|7|8]\d{9}$/.test(tel))) {
            myApp.alert('手机号格式有误');
            return;
        }
        if (pwd === "") {
            myApp.alert('请输入密码');
            return;
        }
        //手机号输入
        $$('.loginView-tel-text').on('input', function () {

            var length = $$('.loginView-tel-text').val().length;
            var text = $$('.loginView-tel-text').val();
            var reg = new RegExp("^[0-9]*$");

            if (!reg.test(text.substring(length - 1, 1))) {

                this.value = text.substring(0, length - 2);
            }
        });

        var url = 'http://120.55.189.165:81/gzb/index.php/Home/Worker/login';
        var data = {worker_mobile: tel, password: pwd, page_no: 0};
        $$.ajax({
            type: "GET",
            dataType: "json",
            async: true,
            url: url,
            data: data,
            success: function (json) {
                var code = json.code;
                var data = json.data;
                if (code === 0) {//登录成功
                    //清空storage
                    localStorage.removeItem("sessionid");
                    //保存登录信息

                    localStorage.setItem("sessionid", data);

                    mainView.router.loadPage("../../yd/Main/main.html");
                }
                else {
                    myApp.alert('登入信息有误');
                }
            },
            error: function (json) {
                myApp.alert("网络错误");
            }
        });
    });

});

//登录忘记密码初始化
$$(document).on('pageInit', function (e) {
    var page = e.detail.page;
    if (page.name === 'forgotPwd') {
        $$('.navbar-inner').css('background-color','transparent');
        if($("#demo").length>0) {
            $$('.navbar-inner').css('background-color','#2E9DB4');
        }
    }
});
//忘记密码
myApp.onPageInit('forgotPwd', function (page) {

    //ajax请求公司logo
    $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/getCompanyLogo', {session_id:localStorage.getItem('sessionid')}, function (data) {
        var obj = eval('(' + data + ')');
        if (obj.code === 1){
            $$(".companyLogo").attr("src", "imgs/3435355_03.png");
        }
        else {
            $$(".companyLogo").attr("src", obj.data);
        }
    });

    $$('.navbar-inner').css('background-color','transparent');
    if($("#demo").length>0) {
        $$('.navbar-inner').css('background-color','#2E9DB4');
    }
    // 点击登录按钮
    $$('.button.button-big.forgotpwd-btn').on('click', function () {
        // 获取用户登录信息
        var tel=$$('.forgotpwd-tel-text').val();
        var newpwd=$$('.forgotpwd-pwd-password').val();
        var code=$$('.forgotpwd-code').val();
        //判断输入信息是否为空
        if(tel===""){
            myApp.alert('请输入手机号');
            return;
        }
        //验证手机号的合法性
        if(!(/^1[3|4|5|7|8]\d{9}$/.test(tel))){
            myApp.alert('手机号格式有误');
            return;
        }
        if(code===""){
            myApp.alert('请输入验证码');
            return;
        }
        if(newpwd===""){
            myApp.alert('请输入密码');
            return;
        }

        var url = 'http://120.55.189.165:81/gzb/index.php/Home/Worker/findPassword';
         var data = {worker_mobile: tel,password:newpwd,cap_code:code};
         $$.ajax({  
             type: "GET", 
             dataType: "json", 
             async: true, 
             url: url, 
             data: data, 
             success: function (json) { 
                 var code = json.code; 
                 if (code === 0) {
                     //修改成功 
                     myApp.hideIndicator(); 
                     myApp.alert(" 修改成功", function(){
                         //保存session_id
                         var url = 'http://120.55.189.165:81/gzb/index.php/Home/Worker/login';
                         var data = {worker_mobile: tel, password:newpwd, page_no: 0};
                         $$.ajax({
                             type: "GET",
                             dataType: "json",
                             async: true,
                             url: url,
                             data: data,
                             success: function (json) {
                                 var code = json.code;
                                 var data = json.data;
                                 if (code === 0) {
                                     //清空storage
                                     localStorage.removeItem("sessionid");
                                     //保存登录信息
                                     localStorage.setItem("sessionid", data);
                                     mainView.router.loadPage("../../yd/Main/main.html");
                                 }
                             },
                             error: function (json) {
                                 //myApp.alert("网络错误");
                             }
                         })
                     }); 
                 } 
                 else{//1是失败 
                      myApp.alert("验证码错误"); 
                 }
             }, 
             error: function (json) { 
                 myApp.alert("网络错误"); 
             } });

    });

    //手机号输入
    $$('.forgotpwd-tel-text').on('input',function(){

        var length= $$('.forgotpwd-tel-text').val().length;
        var text=$$('.forgotpwd-tel-text').val();
        var reg = new RegExp("^[0-9]*$");
        if(!reg.test(text.substring(length-1,1))){

            this.value=text.substring(0,length-2);
        }
    });

    // run createContentPage func after link was clicked
    $$('.forgotpwd-code-btn').on('click',function(){
        var tel=$$('.forgotpwd-tel-text').val();
        if(tel===""){
            myApp.alert('请输入手机号');
            return;
        }
        //验证手机号的合法性
        if(!(/^1[3|4|5|7|8]\d{9}$/.test(tel))){
            myApp.alert('手机号格式有误');
            return;
        }
        time(this);
        //发送验证码
        var url = 'http://120.55.189.165:81/gzb/SendSMS/SendTemplateSMS.php/sendTemplateSMS';
        var data = {mobile: tel,type:1};
        $$.ajax({
            type: "GET",
            dataType: "json",
            async: true,
            url: url,
            data: data,
            success: function (json) {
                var code = json.code;
                if (code === 0) {
                    //发送成功 
                    //myApp.alert(" 发送成功");activateAndLoginView-code-btn
                }
                else{//发送失败 
                    myApp.alert("发送失败");     }    },
            error: function (json) {
                //myApp.alert("网络错误");
            } });
    })

});

//激活
myApp.onPageInit('registerView', function (page) {
    //ajax请求公司logo
    $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/getCompanyLogo', {session_id:localStorage.getItem('sessionid')}, function (data) {
        var obj = eval('(' + data + ')');
        if (obj.code === 1){
            $$(".companyLogo").attr("src", "imgs/3435355_03.png");
        }
        else {
            $$(".companyLogo").attr("src", obj.data);
        }
    });

    // run createContentPage func after link was clicked
    $$('.navbar-inner').css('background-color','transparent');
    if($("#demo").length>0) {
        $$('.navbar-inner').css('background-color','#2E9DB4');
    }
    $$('.button.button-big.loginView-btn').on('click', function () {
        // 获取激活登录信息
        var company=$$('.registerView-company-text').val();
        var pwd=$$('.registerView-pwd-password').val();
        if(company===""){
            myApp.alert("请输入公司编号");
            return;
        }
        if(pwd===""){
            myApp.alert("请输入初始密码");
            return;
        }

        var url = 'http://120.55.189.165:81/gzb/index.php/Home/Worker/active'; 
        var data = {factory_num: company, idcard_six:pwd}; 
        $$.ajax({ 
            type: "GET", 
            dataType: "json", 
            async: true, 
            url: url, 
            data: data, 
            success: function (json) { 
                var code = json.code; 
                if (code === 0) {//激活成功 
                     myApp.hideIndicator(); 
                     myApp.alert("激活成功", function(){ 
                         mainView.router.loadPage({ 
                        url: 'activateAndLoginView.html?data='+json.data+'' 
                       });         });     } 
                 else{//1是失败 
                        myApp.alert(json.msg);

                       }    }, 
                     error: function (json) { 
                         myApp.alert("网络错误"); 
                     }
                              });
    });
});

//倒计时获取验证码
var wait=60;
function time(o) {
    if (wait === 0) {
        o.disabled=false;
        o.value="获取验证码";
        wait = 60;
    } else {
        o.disabled=true;
        o.value="重新发送" + wait + "";
        wait--;
        setTimeout(function() {
                time(o);
            },
            1000)
    }
}

//注册
myApp.onPageInit('activateAndLoginView', function (page) {


    //ajax请求公司logo
    $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/getCompanyLogo', {session_id:localStorage.getItem('sessionid')}, function (data) {
        var obj = eval('(' + data + ')');
        if (obj.code === 1){
            $$(".companyLogo").attr("src", "imgs/3435355_03.png");
        }
        else {
            $$(".companyLogo").attr("src", obj.data);
        }
    });
    $$('.navbar-inner').css('background-color','transparent');
    if($("#demo").length>0) {
        $$('.navbar-inner').css('background-color','#2E9DB4');
    }

    $$('.button.button-big.activateAndLoginView-btn').on('click', function () {
        // 获取注册登录信息
        var tel=$$('.activateAndLoginView-tel-text').val();
        var code=$$('.activateAndLoginView-code').val();
        var pwd=$$('.activateAndLoginView-pwd-password').val();
        //判断输入信息是否为空
        if(tel===""){
            myApp.alert('请输入手机号');
            return;
        }
        //验证手机号的合法性
        if(!(/^1[3|4|5|7|8]\d{9}$/.test(tel))){
            myApp.alert('手机号格式有误');
            return;
        }
        if(code==""){
            myApp.alert('请输入验证码');
            return;
        }
        if(pwd===""){
            myApp.alert('请输入密码');
            return;
        }

        var url = 'http://120.55.189.165:81/gzb/index.php/Home/Worker/Register'; 
        var data = {worker_mobile: tel,password:pwd,cap_code:code,worker_id:page.query.data};
                 $$.ajax({  
                     type: "GET", 
                     dataType: "json", 
                     async: true, 
                     url: url, 
                     data: data, 
                     success: function (json) { 
                         var code = json.code; 
                         if (code === 0) {//注册成功 
                              myApp.hideIndicator(); 
                              myApp.alert(" 注册成功", function(){ 
                                 //保存session_id
                                 var url = 'http://120.55.189.165:81/gzb/index.php/Home/Worker/login';
                                 var data = {worker_mobile: tel, password: pwd, page_no: 0};
                                 $$.ajax({
                                     type: "GET",
                                     dataType: "json",
                                     async: true,
                                     url: url,
                                     data: data,
                                     success: function (json) {
                                         var code = json.code;
                                         var data = json.data;
                                         if (code === 0) {//登录成功
                                             //清空storage
                                             localStorage.removeItem("sessionid");
                                             //保存登录信息

                                             localStorage.setItem("sessionid", data);

                                             mainView.router.loadPage("../../yd/Main/main.html");
                                         }
                                         else {
                                             //myApp.alert('登入信息有误');
                                         }
                                     },
                                     error: function (json) {
                                         //myApp.alert("网络错误");
                                     }
                                 })

                                        });     } 
                         else{//1是失败 
                              myApp.alert(json.msg);
                              }    }, 
                     error: function (json) { 
                         myApp.alert("网络错误");     } });

    });

    //手机号输入
    $$('.activateAndLoginView-tel-text').on('input',function(){

        var length= $$('.activateAndLoginView-tel-text').val().length;
        var text=$$('.activateAndLoginView-tel-text').val()
        var reg = new RegExp("^[0-9]*$");
        if(!reg.test(text.substring(length-1,1))){

            this.value=text.substring(0,length-2);
        }
    });
    // 点击获取验证码按钮
    $$('.activateAndLoginView-code-btn').on('click',function(){
        var tel=$$('.activateAndLoginView-tel-text').val();
        if(tel===""){
            myApp.alert('请输入手机号');
            return;
        }
        //验证手机号的合法性
        if(!(/^1[3|4|5|7|8]\d{9}$/.test(tel))){
            myApp.alert('手机号格式有误');
            return;
        }
        time(this);
        //发送验证码
        var url = 'http://120.55.189.165:81/gzb/SendSMS/SendTemplateSMS.php/sendTemplateSMS';
        var data = {mobile: tel,type:1};
        $$.ajax({
            type: "GET",
            dataType: "json",
            async: true,
            url: url,
            data: data,
            success: function (json) {
                var code = json.code;
                if (code === 0) {
                    //发送成功 
                    //myApp.alert(" 发送成功");
                }
                else{//发送失败 
                    myApp.alert("发送失败");     }    },
            error: function (json) {
                //myApp.alert("网络错误");
            } });
    })



});

//通知栏页码
 var company_page_no=0;
 var wages_page_no=0;
 var leave_page_no=0;
//初始化通知栏界面
$$(document).on('pageInit', function (e) {
    var page = e.detail.page;
    // Code for About page
    if (page.name === 'noticeList') {
        //数据加载－模拟数据
        //公司公告
         company_page_no=0;
         wages_page_no=0;
         leave_page_no=0;

        //公司公告
        var company;
        $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/getBoard', {session_id:localStorage.getItem('sessionid'),type:1, page_size:10,page_no:company_page_no}, function (data) {
            var obj = eval('(' + data + ')');
            var code = obj.code;
            if (code === 0){//成功
                company=obj.data;
                //公司公告
                var companyHtml="";
                for(var i=0;i<company.length;i++){
                    companyHtml+="<li> <a href='../NoticeList/companyView.html?content="+company[i]["annoc_content"]+"&title="+company[i]["annoc_title"]+"' class='item-link item-content'>"+
                        "<div class='item-inner'>"
                        +company[i]["createddate"].substring(0,10)+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+company[i]["annoc_title"]+
                        " </div>"+
                        "</a></li>";
                }
                $$(page.container).find('.table1').append(companyHtml);
                company_page_no++;
            }
        });

        //工资信息
        var wages;
        $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/getBoard', {session_id:localStorage.getItem('sessionid'),type:2, page_size:10,page_no:wages_page_no}, function (data) {
            var obj = eval('(' + data + ')');
            var code = obj.code;
            if (code === 0){//成功
                wages=obj.data;
                var wagesHtml="";
                for(var i=0;i<wages.length;i++){
                    wagesHtml+="<li class='item-content'>"+
                       "<div class='item-inner'>"+
                        "<div class='item-title'><span style='color: gray;font-size: small;'>"+wages[i]["createddate"].substring(0,10)+"</span>&nbsp;&nbsp;&nbsp;&nbsp;提现:"+wages[i]["account_apply_sum"]+"元</div>"
                    if(wages[i]["account_apply_status"]===1){
                        wagesHtml+= "<div class='item-after' style='color:#EEB422;'>审核中</div>"
                    }
                    else{
                        wagesHtml+= "<div class='item-after' style='color:#66CDAA;'>已通过</div>"
                    }
                    wagesHtml+= "</div>"
                    wagesHtml+= "</li>";
                }
                $$(page.container).find('.table2').append(wagesHtml);
                wages_page_no++;
            }
        });

        //请假信息
        var leave;
        $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/getBoard', {session_id:localStorage.getItem('sessionid'),type:3, page_size:10,page_no:wages_page_no}, function (data) {
            var obj = eval('(' + data + ')');
            var code = obj.code;
            if (code === 0){//成功
                leave=obj.data;
                var leaveHtml="";
                for(var i=0;i<leave.length;i++){
                    leaveHtml+="<li class='accordion-item'><a href='#' class='item-content item-link'>"+
                        "<div class='item-inner'>"+
                        "<div class='item-title'><dav style='position: 0;left: 0px;width: 80px;top:0;height: 100%;'><sqan style='color: gray;font-size: small;'>"+leave[i]["createddate"].substring(0,10)+
                        "</sqan>&nbsp;&nbsp;&nbsp;&nbsp;<span>"+leave[i]["vaapply_type"]+"</span>,<span>共计"+leave[i]["vaapply_days"]+"天</span></div><div></div>";
                    if(leave[i]["vaapply_status"]==="1"){

                        leaveHtml+= "<div style='color:#EEB422'>审核中</div></div>";
                    }
                    else if(leave[i]["vaapply_status"]==="3"){
                        leaveHtml+= "<div style='color: red'>不同意</div></div>";
                    }
                    else{
                        leaveHtml+= "<div style='color:#66CDAA'>已通过</div></div>";
                    }

                    leaveHtml+="</div></a>"+
                        "<div class='accordion-item-content'>"+
                        "<div class='content-block' style='background-color: gainsboro'></br>"+
                        "<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;详情:"+leave[i]["vaapply_desc"]+"</span></br></br>" +
                        "<sqan>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;开始时间:"+leave[i]["vaapply_start"]+"</span></br></br>"+
                        "<sqan>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;结束时间:"+leave[i]["vaapply_end"]+"</span></br></br>"+
                        "<sqan>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;合计天数:"+leave[i]["vaapply_days"]+"天</span></br></br>"+
                        "</div>"+
                        "</div>"+
                        "</li>";
                }
                $$(page.container).find('.table3').append(leaveHtml);
                leave_page_no++;
            }
        });
    }
});

//通知栏界面数据加载更多
myApp.onPageInit('noticeList',function (page) {
    $$('.addInfo1').on('click',function(){
        $$('.addInfo1 p').css('display','none');
        $$('.addInfo1 span').css('display','block');
        setTimeout(function() {
                var company;
                $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/getBoard', {session_id:localStorage.getItem('sessionid'),type:1, page_size:5,page_no:company_page_no}, function (data) {
                    var obj = eval('(' + data + ')');
                    var code = obj.code;
                    if (code === 0){//成功
                        company=obj.data;
                        if(company.length===0){
                            myApp.alert('无更多信息');
                            return;
                        }
                        //公司公告
                        var companyHtml="";
                        for(var i=0;i<company.length;i++){
                            companyHtml+="<li> <a href='../NoticeList/companyView.html?content="+company[i]["annoc_content"]+"&title="+company[i]["annoc_title"]+"' class='item-link item-content'>"+
                                "<div class='item-inner'>"
                                +company[i]["createddate"].substring(0,10)+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+company[i]["annoc_title"]+
                                " </div>"+
                                "</a></li>";
                        }
                        $$(page.container).find('.table1').append(companyHtml);
                        company_page_no++;
                    }
                    else{
                        myApp.alert('网络错误');
                    }
                });
                $$('.addInfo1 p').css('display','block');
                $$('.addInfo1 span').css('display','none');
            },
            1000)
        //加载数据
    });
    $$('.addInfo2').on('click',function(){
        $$('.addInfo2 p').css('display','none');
        $$('.addInfo2 span').css('display','block');
        setTimeout(function() {
            var wages;
            var wagesHtml="";
                $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/getBoard', {session_id:localStorage.getItem('sessionid'),type:2, page_size:10,page_no:wages_page_no}, function (data) {
                    var obj = eval('(' + data + ')');
                    var code = obj.code;
                    if (code === 0){//成功
                        wages=obj.data;
                        if(wages.length===0){
                            myApp.alert('无更多信息');
                            return;
                        }
                        for(var i=0;i<wages.length;i++){
                            wagesHtml+="<li class='item-content'>"+
                                "<div class='item-inner'>"+
                                "<div class='item-title'><span style='color: gray;font-size: small;'>"+wages[i]["createddate"].substring(0,10)+"</span>&nbsp;&nbsp;&nbsp;&nbsp;提现:"+wages[i]["account_apply_sum"]+"元</div>"
                            if(wages[i]["account_apply_status"]==1){
                                wagesHtml+= "<div class='item-after' style='color:#EEB422;'>审核中</div>"
                            }
                            else{;
                                wagesHtml+= "<div class='item-after' style='color:#66CDAA;'>已通过</div>"
                            }
                            wagesHtml+= "</div>"
                            wagesHtml+= "</li>";
                        }
                        $$(page.container).find('.table2').append(wagesHtml);
                        wages_page_no++;
                    }
                    else{
                        myApp.alert('网络错误');
                    }
            });
                $$('.addInfo2 p').css('display','block');
                $$('.addInfo2 span').css('display','none');
            },
            1000)
    });
    $$('.addInfo3').on('click',function(){
        $$('.addInfo3 p').css('display','none');
        $$('.addInfo3 span').css('display','block');
        setTimeout(function() {
                var leave;
                var leaveHtml="";
                $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/getBoard', {session_id:localStorage.getItem('sessionid'),type:3, page_size:10,page_no:leave_page_no}, function (data) {
                    var obj = eval('(' + data + ')');
                    var code = obj.code;
                    if (code === 0){//成功
                        leave=obj.data;
                        if(leave.length===0){
                            myApp.alert('无更多信息');
                            return;
                        }
                        for(var i=0;i<leave.length;i++){
                            leaveHtml+="<li class='accordion-item'><a href='#' class='item-content item-link'>"+
                                "<div class='item-inner'>"+
                                "<div class='item-title'><dav style='position: 0;left: 0px;width: 80px;top:0;height: 100%;'><sqan style='color: gray;font-size: small;'>"+leave[i]["createddate"].substring(0,10)+
                                "</sqan>&nbsp;&nbsp;&nbsp;&nbsp;<span>"+leave[i]["vaapply_type"]+"</span>,<span>共计"+leave[i]["vaapply_days"]+"天</span></div><div></div>";
                            if(leave[i]["vaapply_status"]==="1"){

                                leaveHtml+= "<div style='color:#EEB422'>审核中</div></div>";
                            }
                            else if(leave[i]["vaapply_status"]==="3"){
                                leaveHtml+= "<div style='color: red'>不同意</div></div>";
                            }
                            else{
                                leaveHtml+= "<div style='color:#66CDAA'>已通过</div></div>";
                            }

                            leaveHtml+="</div></a>"+
                                "<div class='accordion-item-content'>"+
                                "<div class='content-block' style='background-color: gainsboro'></br>"+
                                "<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;详情:"+leave[i]["vaapply_desc"]+"</span></br></br>" +
                                "<sqan>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;开始时间:"+leave[i]["vaapply_start"]+"</span></br></br>"+
                                "<sqan>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;结束时间:"+leave[i]["vaapply_end"]+"</span></br></br>"+
                                "<sqan>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;合计天数:"+leave[i]["vaapply_days"]+"天</span></br></br>"+
                                "</div>"+
                                "</div>"+
                                "</li>";
                        }
                        leave_page_no++;
                        $$(page.container).find('.table3').append(leaveHtml);
                    }
                    else{
                        myApp.alert('网络错误');
                    }
                });
                $$('.addInfo3 p').css('display','block');
                $$('.addInfo3 span').css('display','none');
            },
            1000)
    });
});

//公司通告详细页面初始化
$$(document).on('pageInit', function (e){
    $$('.navbar-inner').addClass('my-navigation-bar');
    var page = e.detail.page;
    if (page.name === 'companyView') {
        //获取通告标题
        var title=page.query.title;
        // 获取通告内容
        var content = page.query.content;
        var txtShow =content;
        $$(page.container).find('.infoShow').append(txtShow);
        $$(page.container).find('.title').append(title);
    }
});

//yd-----------------------------------------------------------------------------------
//首页滚动的方法
function Marquee(){
    if($("#demo2").length>0) {
        if (demo2.offsetTop - demo.scrollTop <= 0) {
            demo.scrollTop = demo.scrollTop - demo1.offsetHeight;

        }
        else {
            demo.scrollTop++;
            //if(demo.scrollTop%60==0) {
            //    for(var t=Date.now();Date.now()-t<=500;);
            //}
        }
    }
    else
    {
        clearInterval(MyMar);
    }
}
var MyMar;

//主页
$$(document).on('pageInit', '.page[data-page="main"]', function (e) {

    $$('.navbar-inner').addClass('my-navigation-bar');
    $$(".page").addClass("no-swipeback");
    $("#footer").animate({bottom:'0px'},600,function(){

    });

    //获取首页信息
    var url='http://120.55.189.165:81/gzb/index.php/Home/Worker/getMainData';
    var data={session_id:localStorage.getItem('sessionid')};
    $$.ajax({
        type: "GET",
        dataType : "json",
        async: true,
        url: url,
        data:{session_id:localStorage.getItem('sessionid')},
        success: function(json) {
            var data = json.data;
            var code=json.code;
            if(code=='0') {
                $('.rateAmount').html(data.rate + "%");
                $('.incomeAmount').html(data.income);
                if (data.total.length >= 7) {
                    $('.lable2,.lable22,.lable222').css('font-size', '20px');
                }
                $('.lable2').html(data.total);
                $('.lable22').html(data.vacation_days);
                $('.lable222').html(data.profit);
            }
        },
        error: function(json) {

        }
    });

    //滚动条
    var url2="http://120.55.189.165:81/gzb/index.php/Home/Worker/getMainBoard";
    $.ajax({
        type: "GET",
        dataType: "json",
        async: true,
        url: url2,
        data:data,
        success: function(json) {
            //获取首页滚动条的数据
            var html="";
            var data2=json.data.factory_annoc;
            var code=json.code;
            if(code=='0') {
                if(data2.length>0) {
                    for (var i = 0; i < data2.length; i++) {
                        html += '<li style="width: 100%;height: 50px;line-height: 50px;">' +
                            '<img style="width: 17px;height: 16px;" src="../image/Main/horn.png"/>' +
                            '<span style="margin-left: 15%;font-size: 20px;">' + data2[i].annoc_title + '</span>' +
                            '</li>';
                    }
                }
                else
                {
                    for (var i = 0; i < 2; i++) {
                        html += '<li style="width: 100%;height: 50px;line-height: 50px;">' +
                            '<img style="width: 17px;height: 16px;" src="../image/Main/horn.png"/>' +
                            '<span style="margin-left: 15%;font-size: 20px;">暂无通知</span>' +
                            '</li>';
                    }
                }

            }
            else
            {
                for (var i = 0; i < 2; i++) {
                    html += '<li style="width: 100%;height: 50px;line-height: 50px;">' +
                        '<img style="width: 17px;height: 16px;" src="../image/Main/horn.png"/>' +
                        '<span style="margin-left: 15%;font-size: 20px;">暂无通知</span>' +
                        '</li>';
                }
            }
            $("#factory_annoc").append(html);
            var speed = 60;
            demo2.innerHTML = demo1.innerHTML;
            MyMar = setInterval(Marquee, speed);
        },
        error: function(json) {
            myApp.alert('网络错误，请检查网络');
        }
    });
});

//工资总额
$$(document).on('pageInit','.page[data-page="PayTotal2"]', function (e) {

    $$('.navbar-inner').addClass('my-navigation-bar');
    //点击加载更多
    $('.load').on('click',function(){
        loadmore();
    });

    $('.load').trigger("click");

    // 加载flag
    var loading = false;
// 上次加载的序号
    var lastIndex = $$('.pay_cells .pay_cell').length;

    //几个月
    $$('.mouthCount').html(lastIndex+"个月");

    //拿到资金总额
    var url2='http://120.55.189.165:81/gzb/index.php/Home/Worker/getAccount';
    var data2={session_id:localStorage.getItem('sessionid')};
    $$.ajax({
        type: "GET",
        dataType: "json",
        async: true,
        url: url2,
        data:data2,
        success: function(json) {
            var html = '';
            var data = json.data;
            $$('.payCount').html(data.total);
        },
        error: function(json) {
            myApp.alert("请求失败,请检查网络");
        }
    });

    function loadmore() {
        // 如果正在加载，则退出
        if (loading) return;
        // 设置flag
        loading = true;

        $('.infinite-scroll-preloader').css('display', 'block');
        $('.loadmore').css('display', 'none');

        //获取工资发放列表
        var url= 'http://120.55.189.165:81/gzb/index.php/Home/Worker/salaryLog';
        var page_size=5;
        var page_no=lastIndex/5;
        var data={session_id:localStorage.getItem('sessionid'),page_size:page_size,page_no:page_no};
        $$.ajax({
            type: "GET",
            dataType: "json",
            async: true,
            url: url,
            data:data,
            success: function(json) {
                var html = '';
                var data = json.data;
                for (var i = 0; i < data.length; i++) {
                    html += '<div class="pay_cell">' +
                        '<div class="cell_day">' +
                        '<img src="../image/PayTotal/paytotal_line.png"/>' +
                        '<div class="day">' +
                        data[i].created_date.substring(0,7) +
                        '</div>' +
                        '<img src="../image/PayTotal/paytotal_line.png"/>' +
                        '</div>' +
                        '<div class="cell_pay">' +
                        '<div class="pay selected">' +
                        '<span class="newlable" style="display:none;">新</span>' +
                        '<span class="monlable">' + data[i].created_date.substring(6, 7) + '月工资</span>' +
                        '<span class="countlable">' + data[i].salary + '</span>' +
                        '</div>' +
                        '</div>' +
                        '</div>';
                }
                $('.infinite-scroll-preloader').css('display', 'none');

                $('.loadmore').css('display', 'block');
                // 添加新条目
                $$('.pay_cells').append(html);

                // 更新最后加载的序号
                lastIndex = $$('.pay_cells .pay_cell').length;

                $('.newlable:first').css('display', 'inline');

                $$('.mouthCount').html(lastIndex + "个月");

                loading = false;
                if(data.length==0) {
                    myApp.alert("无更多数据");
                }
            },
            error: function(json) {
                $$('.infinite-scroll-preloader').css('display','none');
                myApp.alert("请求失败,请检查网络");
            }
        });
    };
});

//账户详单
$$(document).on('pageInit','.page[data-page="accountdetails"]', function (e) {

    $$('.navbar-inner').addClass('my-navigation-bar');
    //点击加载更多
    $('.load1').on('click',function(){
        loadmore();
    });

    $('.load1').trigger("click");

    // 加载flag
    var loading = false;
// 上次加载的序号
    var lastIndex = $$('.accordion-item').length;

    function loadmore() {
        // 如果正在加载，则退出
        if (loading) return;
        // 设置flag
        loading = true;

        $('.infinite-scroll-preloader').css('display', 'block');
        $('.loadmore').css('display', 'none');

        //获取工资发放列表
        var url='http://120.55.189.165:81/gzb/index.php/Home/Worker/accountLog';
        var page_size=6;
        var page_no=lastIndex/6;
        var data={session_id:localStorage.getItem('sessionid'),page_size:page_size,page_no:page_no};
        $$.ajax({
            type: "GET",
            dataType: "json",
            async: true,
            url: url,
            data:data,
            success: function(json) {
                var html = '';
                var data = json.data;
                //alert(data);
                for (var i = 0; i < data.length; i++) {
                    html+='<li class="accordion-item">'+
                        '<a href="" class="item-link item-content">'+
                        '<div class="item-inner">'+
                        '<div class="item-title">'+data[i].createddate.substring(0,10)+'</div>'+
                        '<div class="item-title" style="width: 44%;">'+data[i].desc+'</div>';
                            if(data[i].in_out=='0'){
                                html+='<div class="item-title"><span class="titlegreen">+'+data[i].amount+'</span></div>';
                            }
                            else {
                                html+='<div class="item-title"><span class="titlered">-'+data[i].amount+'</span></div>';
                            }
                    html+='</div>'+
                        '</a>'+
                        '<div class="accordion-item-content" style="background-color: #e3e3e3;">';
                    if(data[i].in_out=='0') {
                       html+= '<div class="titlediv titlegreen">收入</div>';
                    }
                    else {
                        html+='<div class="titlediv titlered">支出</div>';
                    }
                       html+='<div class="titlediv">类型:'+data[i].type+'</div>'+
                        '<div class="titlediv">金额:'+data[i].amount+'</div>'+
                        '<div class="titlediv">操作后剩余金额:'+data[i].balance+'</div>'+
                        '</div>'+
                        '</li>';
                }
                $('.infinite-scroll-preloader').css('display', 'none');

                $('.loadmore').css('display', 'block');
                // 添加新条目
                $$('.uldetails').append(html);

                // 更新最后加载的序号
                lastIndex = $$('.accordion-item').length;
                loading = false;
                if(data.length==0) {
                    myApp.alert("无更多数据");
                }
            },
            error: function(json) {
                $$('.infinite-scroll-preloader').css('display','none');
                myApp.alert("请求失败,请检查网络");
            }
        });
    };

});

//请假单
$$(document).on('pageInit', '.page[data-page="offwork"]', function(e){

    var apply_type="";
    var startTime="";
    var endTime="";

    var url2='http://120.55.189.165:81/gzb/index.php/Home/Worker/getWorkerInfo';
    $.ajax({
        type: "GET",
        dataType: "json",
        async: true,
        url: url2,
        data:{session_id:localStorage.getItem("sessionid")},
        success: function(json) {
            var code = json.code;
            var data=json.data;
            if(code=='0'){
                $$('.txtname').val(data.worker_name);
                $$('.txtnumber').val(data.worker_num);
                $$('.txtzhiwu').val(data.position);
                $$('.txtdep').val(data.department);
            }
        },
        error: function(json) {

        }
    });

    $('.submit').on('click',function(){
        var apply_desc=$('.apple_desc').val();
        var vaapply_days=$('#day').val();

        if(apply_type==""||apply_desc==""||startTime==""||vaapply_days==""||vaapply_days<=0||isNaN(vaapply_days)){
            myApp.alert("请选择正确的请假信息");
        }
        else
        {
            var url='http://120.55.189.165:81/gzb/index.php/Home/Worker/vaapply';
            var data={session_id:localStorage.getItem('sessionid'),vaapply_type:apply_type, vaapply_desc:apply_desc,
                vaapply_start:startTime,vaapply_end:endTime,vaapply_days:vaapply_days};
            $.ajax({
                type: "GET",
                dataType: "json",
                async: true,
                url: url,
                data:data,
                success: function(json) {
                    var data = json.code;
                    myApp.alert(json.msg);

                },
                error: function(json) {
                    myApp.alert("请假失败,请检查网络");
                }
            });
        }

    });

    function fix(num, length) {
        return ('' + num).length < length ? ((new Array(length + 1)).join('0') + num).slice(-length) : '' + num;
    }

    //选择请假类型
    var hasclick=false;
    var num=0;
    var arrtype=["年假","婚假","产假","丧假","病假","事假","休假","其他"];
    $(".icon").click(function(){
        var index=$(this).data("index");

        //alert(index);
        if(!hasclick) {
            $(this).find("img").attr('src', '../image/OffWork/offwork_02.png');
            hasclick=true;
            num=index;
        }
        else
        {
            if(num==index){
                $(this).find("img").attr('src', '../image/OffWork/offwork_01.png');
                hasclick=false;
            }
            else
            {
                $(".icon").find("img").attr('src', '../image/OffWork/offwork_01.png');
                $(this).find("img").attr('src', '../image/OffWork/offwork_02.png');
                hasclick=true;
                num=index;
            }
        }
        if(hasclick){
            apply_type= arrtype[index];
        }
        else
        {
            apply_type="";
        }
    });

    $(".picker").val("");
    var today = new Date();
    var pickerDeviceStart = myApp.picker({
        input: '#pick-start',
        //container: '#pick-start-container',
        toolbar: true,
        rotateEffect: true,
        toolbarCloseText: '确定',

        value: [today.getFullYear(), today.getMonth(), today.getDate(), today.getHours()],

        //onChange: function (picker, values, displayValues) {
        //        var daysInMonth = new Date(picker.value[2], picker.value[0]*1 + 1, 0).getDate();
        //        if (values[1] > daysInMonth) {
        //                picker.cols[1].setValue(daysInMonth);
        //        }
        //},
        onClose: function(p){
            var startDate = new Date(pickerDeviceStart.value[0], pickerDeviceStart.value[1], pickerDeviceStart.value[2]);
            var endDate = new Date(pickerDeviceEnd.value[0], pickerDeviceEnd.value[1], pickerDeviceEnd.value[2]);

            //开始时间
            var d1=parseInt(pickerDeviceStart.value[1])+1;
            var d2=parseInt(pickerDeviceEnd.value[1])+1;
            startTime= pickerDeviceStart.value[0]+"-"+fix(d1,2)+"-"+pickerDeviceStart.value[2];
            //结束时间
            endTime=pickerDeviceEnd.value[0]+"-"+fix(d2,2)+"-"+pickerDeviceEnd.value[2];

            var day = (endDate.getTime() - startDate.getTime())/(24 * 60 * 60 * 1000);
            $$("#day").val(day);
        },

        formatValue: function (p, values, displayValues) {
            return values[0] + '年' + (parseInt(values[1])+1) + '月' + values[2] + '日' + values[3] + '时';
        },

        cols: [
            // Years
            {
                values: (function () {
                    var arr = [];
                    for (var i = 1950; i <= 2030; i++) { arr.push(i); }
                    return arr;
                })(),
            },
            // Months
            {
                //values: ('1 2 3 4 5 6 7 8 9 10 11 12').split(' '),
                //displayValues: ('一月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月 十二月').split(' '),
                //textAlign: 'left'
                values: ('0 1 2 3 4 5 6 7 8 9 10 11').split(' '),
                displayValues: ('一月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月 十二月').split(' '),
                textAlign: 'left'
            },
            // Days
            {
                //values: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31],
                values: ('1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31').split(' '),
                displayValues: ('1日 2日 3日 4日 5日 6日 7日 8日 9日 10日 11日 12日 13日 14日 15日 16日 17日 18日 19日 20日 21日 22日 23日 24日 25日 26日 27日 28日 29日 30日 31日').split(' '),
                textAlign: 'right'
            },
            // Hours
            {
                values: (function () {
                    var arr = [];
                    for (var i = 0; i <= 23; i++) { arr.push(i); }
                    return arr;
                })(),
                displayValues: (function(){
                    var arr = [];
                    for (var i = 0; i <= 23; i++) { arr.push(i + '时'); }
                    return arr;
                })()
            }
        ]
    });

    var pickerDeviceEnd = myApp.picker({
        input: '#pick-end',
        //container: '#pick-start-container',
        toolbar: true,
        rotateEffect: true,
        toolbarCloseText: '确定',

        value: [today.getFullYear(), today.getMonth(), today.getDate(), today.getHours()],

        //onChange: function (picker, values, displayValues) {
        //        var daysInMonth = new Date(picker.value[2], picker.value[0]*1 + 1, 0).getDate();
        //        if (values[1] > daysInMonth) {
        //                picker.cols[1].setValue(daysInMonth);
        //        }
        //},
        onClose: function(p){
            var startDate = new Date(pickerDeviceStart.value[0], pickerDeviceStart.value[1], pickerDeviceStart.value[2]);
            var endDate = new Date(pickerDeviceEnd.value[0], pickerDeviceEnd.value[1], pickerDeviceEnd.value[2]);
            //开始时间
            var d1=parseInt(pickerDeviceStart.value[1])+1;
            var d2=parseInt(pickerDeviceEnd.value[1])+1;
            startTime= pickerDeviceStart.value[0]+"-"+fix(d1,2)+"-"+pickerDeviceStart.value[2];
            //结束时间
            endTime=pickerDeviceEnd.value[0]+"-"+fix(d2,2)+"-"+pickerDeviceEnd.value[2];

            var day = (endDate.getTime() - startDate.getTime())/(24 * 60 * 60 * 1000);
            $$("#day").val(day);
        },

        formatValue: function (p, values, displayValues) {
            return values[0] + '年' + (parseInt(values[1])+1) + '月' + values[2] + '日' + values[3] + '时';
        },

        cols: [
            // Years
            {
                values: (function () {
                    var arr = [];
                    for (var i = 1950; i <= 2030; i++) { arr.push(i); }
                    return arr;
                })(),
            },
            // Months
            {
                //values: ('1 2 3 4 5 6 7 8 9 10 11 12').split(' '),
                //displayValues: ('一月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月 十二月').split(' '),
                //textAlign: 'left'
                values: ('0 1 2 3 4 5 6 7 8 9 10 11').split(' '),
                displayValues: ('一月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月 十二月').split(' '),
                textAlign: 'left'
            },
            // Days
            {
                //values: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31],
                values: ('1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31').split(' '),
                displayValues: ('1日 2日 3日 4日 5日 6日 7日 8日 9日 10日 11日 12日 13日 14日 15日 16日 17日 18日 19日 20日 21日 22日 23日 24日 25日 26日 27日 28日 29日 30日 31日').split(' '),
                textAlign: 'right'
            },
            // Hours
            {
                values: (function () {
                    var arr = [];
                    for (var i = 0; i <= 23; i++) { arr.push(i); }
                    return arr;
                })(),
                displayValues: (function(){
                    var arr = [];
                    for (var i = 0; i <= 23; i++) { arr.push(i + '时'); }
                    return arr;
                })()
            }

            // Minutes
            //{
            //        values: (function () {
            //                var arr = [];
            //                for (var i = 0; i <= 59; i++) { arr.push(i < 10 ? '0' + i : i); }
            //                return arr;
            //        })(),
            //}
        ]
    });
});

//年假天数
$$(document).on('pageInit', '.page[data-page="leavedays"]', function (e) {

    $$('.navbar-inner').addClass('my-navigation-bar');
    //点击加载更多
    $('.load').on('click',function(){
        loadmore();
    });

    $('.load').trigger("click");

    // 注册'infinite'事件处理函数
    //$$('.infinite-scroll').on('infinite', function () {
    //    loadmore();
    //});

    // 加载flag
    var loading = false;

// 上次加载的序号
    var lastIndex = $$('.list-block li').length;

    //拿到资金总额
    var url2='http://120.55.189.165:81/gzb/index.php/Home/Worker/getAccount';
    //var data2={session_id:session_id};
    $$.ajax({
        type: "GET",
        dataType: "json",
        async: true,
        url: url2,
        data:{session_id:localStorage.getItem('sessionid')},
        success: function(json) {
            var html = '';
            var data = json.data;
            getDays(data.vacation_days);
        },
        error: function(json) {
            myApp.alert("请求失败,请检查网络");
        }
    });

    function loadmore(){
        // 如果正在加载，则退出
        if (loading) return;
        // 设置flag
        loading = true;

        $('.infinite-scroll-preloader').css('display','block');
        $('.loadmore').css('display','none');

        //获取工资发放列表
        var url= 'http://120.55.189.165:81/gzb/index.php/Home/Worker/vacationLog';
        var page_size='5';
        var page_no=lastIndex/5;

        var data={session_id:localStorage.getItem('sessionid'),page_size:page_size,page_no:page_no};

        $$.ajax({
            type: "GET",
            dataType: "json",
            async: true,
            url: url,
            data:data,
            success: function(json) {
                var data = json.data;
                var html='';
                for(var i=0;i<data.length;i++){
                    html += '<li class="item-content">'+
                        '<div class="item-inner">'+
                        '<div class="li_left">'+
                        '<div class="circle">'+
                        '</div>'+
                        '</div>'+
                        '<div class="li_right">'+
                        '<div class="left_info">'+
                        data[i].createddate.substring(0,10)+
                        '</div>'+
                        '<div class="centre_info">'+
                        data[i].content+
                        '</div>'+
                        '<div class="right_info">';
                    if(data[i].change>0){
                        html+='+'+data[i].change;
                    }else
                    {
                        html+=data[i].change;
                    }
                      html+='</div>'+
                          '</div>'+
                          '</div>'+
                          '</li>';
                }

                $('.infinite-scroll-preloader').css('display','none');

                $('.loadmore').css('display','block');
                // 添加新条目
                $$('.list-block ul').append(html);

                loading = false;
                if(data.length==0) {
                    myApp.alert("无更多数据");
                }

                // 更新最后加载的序号
                lastIndex = $$('.list-block li').length;
            },
            error: function(json) {
                $$('.infinite-scroll-preloader').css('display','none');
                myApp.alert("网络错误");
            }
        });
    };

    //从服务器拿到年假天数，然后做一个从0到days的动画
    function getDays (days) {
        //用到了countUp.js的插件
        var options = {
            useEasing: true,
            useGrouping: true,
            separator: ',',
            decimal: '.',
            prefix: '',
            suffix: ''
        };
        var demo = new CountUp("offdays", 0, days, 0, 2, options);
        demo.start();
    };

});

//工资收益
$$(document).on('pageInit', '.page[data-page="payincome2"]', function (e) {

    $$('.navbar-inner').addClass('my-navigation-bar');
    //点击加载更多
    $('.load').on('click',function(){
        loadmore();
    });

    $('.load').trigger("click");

    // 加载flag
    var loading = false;
// 上次加载的序号
    var lastIndex = $$('.payincomemain .payincomeinfos').length;

    function loadmore(){
        // 如果正在加载，则退出
        if (loading) return;
        // 设置flag
        loading = true;

        $('.infinite-scroll-preloader').css('display','block');
        $('.loadmore').css('display','none');

        var url='http://120.55.189.165:81/gzb/index.php/Home/Worker/profitLog';
        var page_size=5;
        var data={session_id:localStorage.getItem('sessionid'),page_size:page_size};
        $$.ajax({
            type: "GET",
            dataType: "json",
            async: true,
            url: url,
            data:{session_id:localStorage.getItem('sessionid'),page_size:page_size},
            success: function(json) {
                var html='';
                var data=json.data;

                if(data.length<=0)
                {
                    $$('.infinite-scroll-preloader').css('display','none');
                    myApp.alert("暂无数据");
                }
                else
                {
                    for(var j=0;j<data.length;j++) {
                        html += '<div class="payincomeinfos">';
                        html+= '<div class="payincometitle">' +
                            '<div class="payincomemonthcount">' + data[j][0].createddate.substring(6, 7) + '</div>' +
                            '<div class="payincomemonthpay">月工资收益</div>' +
                            '<img src="../image/Income/income_cell_open.png"/>' +
                            '</div>';
                        html+='<ul class="payincomeinfoul" style="display: none;">';
                        for (var i = 0; i < data[j].length; i++) {


                            html+='<li>' +
                                '<span class="incomelable">' + data[j][i].createddate.substring(6, 10) + '工资收益</span>' +
                                '<span class="incomelable2">+'+data[j][i].income+'</span>' +
                                '</li>';

                        }
                        html+='</ul></div>';
                    }

                    $(".payincomemain").unbind('click').on('click','.payincometitle',function(){
                        if($(this).next().css("display")=="none")
                        {
                            $(this).next().show();
                            $(this).children("img").attr("src","../image/Income/income_cell_toopen.png");
                        }
                        else
                        {
                            $(this).next().hide();
                            $(this).children("img").attr("src","../image/Income/income_cell_open.png");
                        }
                    });

                    $$('.infinite-scroll-preloader').css('display','none');
                    //$('.loadmore').css('display','block');

                    // 添加新条目
                    $$('.payincomemain').append(html);

                    // 重置加载flag
                    loading = false;

                    // 更新最后加载的序号
                    lastIndex = $$('.payincomemain .payincomeinfos').length;
                }

            },
            error: function(json) {
                $$('.infinite-scroll-preloader').css('display','none');
                myApp.alert("请求失败,请检查网络");
            }
        });
    };

});

//年假规则
$$(document).on('pageInit', '.page[data-page="annualrule"]', function (e) {
    $$('.navbar-inner').addClass('my-navigation-bar');

    var url='http://120.55.189.165:81/gzb/index.php/Home/Worker/getFactoryInfo';
    $$.ajax({
        type: "GET",
        dataType: "json",
        async: true,
        url: url,
        data:{session_id:localStorage.getItem('sessionid')},
        success: function(json) {
            var html='';
            var data=json.data;
            var code=json.code;
            if(code=='0') {
                $$('.spanmoney').html(data.vaca_money);
                $$('.spandays').html(data.vaca_month);
            }
        },
        error: function(json) {
            myApp.alert("请求失败,请检查网络");
        }
    });
});

//————————————————————————————————————————————————————————————————————————————————————————————————————————————
//dj
function ajaxget(session_id,password,newPassword){
    myApp.showIndicator();
    $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/modifyPassword', {session_id:session_id,password:password,newPassword:newPassword}, function (data) {
        var obj = eval('(' + data + ')');
        var code = obj.code;
        myApp.hideIndicator();
        if (code === 0){
            myApp.alert("修改成功", function(){
                mainView.router.back({
                    url: '../../dj/work-permit.html',
                    force: true
                });
            });
        }
        else{
            myApp.alert("修改失败", function(){
                mainView.router.back({
                    url: '../../dj/work-permit.html',
                    force: true
                });
            });
        }
    });
};

$$(document).on('pageInit', function (e) {
    // Get page data from event data
    var page = e.detail.page;

    if (page.name === 'details') {
        // Following code will be executed for page with data-page attribute equal to "about"
        $("#save").unbind("click");
        $("#save").css("color", "#7ac2d1");
        //$("#textValue").attr("autofocus", "autofocus");

        var id = page.query["id"];
        if (id === "0"){
            var idcard = sessionStorage.getItem("idcard");
            $("#navTitle").html("身份证号");
            if (idcard === "undefined"){
                $("#textValue").val("");
            }
            else {
                $("#textValue").val(idcard);
            }
            $("#remark").html("备注:请务必填写本人身份证,如若不是本人身份证,工资出现错误后果自负.");

            //为输入框监听改变事件
            $("#textValue").bind("input propertychange", function(){
                //$("#save").unbind("click");
                if ($(this).val() != idcard && $(this).val() != ""){
                    $("#save").unbind("click");
                    $("#save").css("color", "white");
                    $("#save").bind("click", function(){
                        //执行身份证修改操作
                        //判断身份证格式是否正确
                        var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                        var textValue = $$("#textValue").val();
                        if (reg.test(textValue) === false){//格式错误
                            myApp.alert("身份证格式有误");
                        }
                        else{//格式正确
                            var id_card = $$("#textValue").val();
                            myApp.showIndicator();
                            $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/saveIdcard', {idcard:id_card, session_id:localStorage.getItem('sessionid')}, function (data) {
                                var obj = eval('(' + data + ')');
                                var code = obj.code;
                                myApp.hideIndicator();
                                if (code === 0){
                                    myApp.alert("修改成功", function(){
                                        mainView.router.back({
                                            url: '../../dj/work-permit.html',
                                            force: true
                                        });
                                    });
                                }
                                else{
                                    myApp.alert("修改失败", function(){
                                        mainView.router.back({
                                            url: '../../dj/work-permit.html',
                                            force: true
                                        });
                                    });
                                }
                            });
                        }
                    });
                }
                else{
                    $("#save").unbind("click");
                    $("#save").css("color", "#7ac2d1");
                }

                if ($(this).val() == ""){
                    $(this).attr("placeholder", "请输入身份证号");
                }
            });
        }
        if (id === "1"){
            var phone = sessionStorage.getItem("phone");
            $("#navTitle").html("联系电话");
            if (phone === "undefined"){
                $("#textValue").val("");
            }
            else {
                $("#textValue").val(phone);
            }

            //为输入框监听改变事件
            //不允许用户输入字母
            $$("#textValue").on("input", function(){
                if (isNaN($$(this).val())){
                    var phoneValue = $$(this).val();
                    var newPhoneValue =phoneValue.substring(0,phoneValue.length-1);
                    $$(this).val(newPhoneValue);
                }
            });

            //验证手机格式
            $("#textValue").bind("input propertychange", function(){
                //$("#save").unbind("click");
                if ($(this).val() != phone && $(this).val() != ""){
                    $("#save").unbind("click");
                    $("#save").css("color", "white");
                    $("#save").bind("click", function(){
                        //执行联系电话修改操作
                            //var phone = $$("#textValue").val();
                            //myApp.showIndicator();
                            //$$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/saveContactInfo', {contactInfo:phone, session_id: sessionId}, function (data) {
                            //    var obj = eval('(' + data + ')');
                            //    var code = obj.code;
                            //    if (code === 0){
                            //        myApp.hideIndicator();
                            //        myApp.alert("修改成功");
                            //    }
                            //});

                            var phone = $$("#textValue").val();
                            myApp.showIndicator();
                            $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/saveContactInfo', {contactInfo:phone, session_id:localStorage.getItem('sessionid')}, function (data) {
                                var obj = eval('(' + data + ')');
                                var code = obj.code;
                                myApp.hideIndicator();
                                if (code === 0){
                                    myApp.alert("修改成功", function(){
                                        mainView.router.back({
                                            url: '../../dj/work-permit.html',
                                            force: true
                                        });
                                    });
                                }
                                else{
                                    myApp.alert("修改失败", function(){
                                        mainView.router.back({
                                            url: '../../dj/work-permit.html',
                                            force: true
                                        });
                                    });
                                }
                            });


                    });
                }
                else{
                    $("#save").unbind("click");
                    $("#save").css("color", "#7ac2d1");
                }

                if ($(this).val() == ""){
                    $(this).attr("placeholder", "请输入联系电话");
                }
            });
        }
        if (id === "2"){
            var depart = sessionStorage.getItem("depart");
            $("#navTitle").html("所在部门");
            if (depart === "undefined"){
                $("#textValue").val("");
            }
            else {
                $("#textValue").val(depart);
            }
            //为输入框监听改变事件
            $("#textValue").bind("input propertychange", function(){
                //$("#save").unbind("click");
                if ($(this).val() != depart && $(this).val() != ""){
                    $("#save").unbind("click");
                    $("#save").css("color", "white");
                    $("#save").bind("click", function(){
                        //执行所在部门修改操作
                        var depart = $$("#textValue").val();
                        myApp.showIndicator();
                        $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/saveDepartment', {department:depart, session_id:localStorage.getItem('sessionid')}, function (data) {
                            var obj = eval('(' + data + ')');
                            var code = obj.code;
                            myApp.hideIndicator();
                            if (code === 0){
                                myApp.alert("修改成功", function(){
                                    mainView.router.back({
                                        url: '../../dj/work-permit.html',
                                        force: true
                                    });
                                });
                            }
                            else{
                                myApp.alert("修改失败", function(){
                                    mainView.router.back({
                                        url: '../../dj/work-permit.html',
                                        force: true
                                    });
                                });
                            }
                        });
                    });
                }
                else{
                    $("#save").unbind("click");
                    $("#save").css("color", "#7ac2d1");
                }

                if ($(this).val() == ""){
                    $(this).attr("placeholder", "请输入所在部门");
                }
            });
        }
        if (id === "3"){
            var homeaddress = sessionStorage.getItem("homeaddress");
            $("#navTitle").html("家庭住址");
            if (homeaddress === "undefined"){
                $("#textValue").val("");
            }
            else {
                $("#textValue").val(homeaddress);
            }

            //为输入框监听改变事件
            $("#textValue").bind("input propertychange", function(){
                //$("#save").unbind("click");
                if ($(this).val() != homeaddress && $(this).val() != ""){
                    $("#save").unbind("click");
                    $("#save").css("color", "white");
                    $("#save").bind("click", function(){
                        //执行家庭住址修改操作
                        var address = $$("#textValue").val();
                        myApp.showIndicator();
                        $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/saveAddress', {address:address, session_id:localStorage.getItem('sessionid')}, function (data) {
                            var obj = eval('(' + data + ')');
                            var code = obj.code;
                            myApp.hideIndicator();
                            if (code === 0){
                                myApp.alert("修改成功", function(){
                                    mainView.router.back({
                                        url: '../../dj/work-permit.html',
                                        force: true
                                    });
                                });
                            }
                            else{
                                myApp.alert("修改失败", function(){
                                    mainView.router.back({
                                        url: '../../dj/work-permit.html',
                                        force: true
                                    });
                                });
                            }
                        });

                    });
                }
                else{
                    $("#save").unbind("click");
                    $("#save").css("color", "#7ac2d1");
                }

                if ($(this).val() == ""){
                    $(this).attr("placeholder", "请输入家庭住址");
                }
            });
        }
    }

    if (page.name === 'cash'){
        $("#submitCash").unbind("click");
        $("#submitCash").css("color", "#7ac2d1");

        $$("#cash").on("input", function(){
            if (isNaN($$(this).val())){
                var value = $$(this).val();
                var newValue =value.substring(0,value.length-1);
                if (newValue.length === 0){
                    $("#submitCash").unbind("click");
                    $("#submitCash").css("color", "#7ac2d1");
                    $$(this).val(newValue);
                }
                else{
                    $$(this).val(newValue);
                }
            }
        });

        $("#cash").bind("input propertychange", function(){
            if ($(this).val() != ""){
                $("#submitCash").unbind("click");
                $("#submitCash").css("color", "white");
                $("#submitCash").bind("click", function(){
                    //执行联系电话修改操作
                    var cash = $$("#cash").val();
                    myApp.showIndicator();
                    $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/accountApply', {
                        account_apply_sum: cash,
                        session_id: localStorage.getItem('sessionid'),
                        account_apply_desc: ""
                    }, function (data) {
                        var obj = eval('(' + data + ')');
                        var code = obj.code;
                        myApp.hideIndicator();
                        if (code === 0) {
                            myApp.alert("提现申请成功", function () {
                                mainView.router.back({
                                    url: '../../dj/work-permit.html',
                                    force: true
                                });
                            });
                        }
                        else{
                            myApp.alert("提现失败", function () {
                                mainView.router.back({
                                    url: '../../dj/work-permit.html',
                                    force: true
                                });
                            });
                        }
                    });


                });
            }
            else{
                $("#submitCash").unbind("click");
                $("#submitCash").css("color", "#7ac2d1");
            }

            if ($(this).val() == ""){
                $(this).attr("placeholder", "请输入联系电话");
            }
        });

        var workName = sessionStorage.getItem("workName");
        var workNum = sessionStorage.getItem("workNum");
        var job = sessionStorage.getItem("job");
        var depart = sessionStorage.getItem("depart");

        if (workName === "undefined"){
            $$("#workName").attr("value", "");
        }
        else {
            $$("#workName").attr("value", workName);
        }

        if (workNum === "undefined"){
            $$("#workNum").attr("value", "");
        }
        else {
            $$("#workNum").attr("value", workNum);
        }

        if (job === "undefined"){
            $$("#job").attr("value", "");
        }
        else {
            $$("#job").attr("value", job);
        }

        if (depart === "undefined"){
            $$("#depart").attr("value", "");
        }
        else {
            $$("#depart").attr("value", depart);
        }
    }

    if (page.name === 'work-permit'){
        //ajax请求公司logo
        $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/getCompanyLogo', {session_id:localStorage.getItem('sessionid')}, function (data) {
            var obj = eval('(' + data + ')');
            if (obj.code === 1){
                $$("#companyLogo").attr("src", "../../dj/imgs/3435355_03.png");
            }
            else {
                $$("#companyLogo").attr("src", obj.data);
            }
        });


        //ajax请求数据
        //myApp.showIndicator();
        $$.get('http://120.55.189.165:81/gzb/index.php/Home/Worker/getWorkerInfo', {session_id:localStorage.getItem('sessionid')}, function (data) {
            //myApp.hideIndicator();
            var obj = eval('(' + data + ')');
            var worker_name = obj.data["worker_name"];
            var worker_num = obj.data["worker_num"];
            //var worker_mobile = obj.data["worker_mobile"];
            var department = obj.data["department"];
            var address = obj.data["address"];
            var idcard = obj.data["idcard"];
            var position = obj.data["position"];
            var contact_info = obj.data["contact_info"];
            if (idcard === undefined) {
                $$("#idcard").html("需完善");
            }
            else{
                $$("#idcard").html(idcard);
            }

            if (contact_info === undefined) {
                $$("#contact_info").html("需完善");
            }
            else{
                $$("#contact_info").html(contact_info);
            }

            if (department === undefined) {
                $$("#department").html("需完善");
            }
            else{
                $$("#department").html(department);
            }

            if (address === undefined) {
                $$("#address").html("需完善");
            }
            else{
                $$("#address").html(address);
            }

            $$("#worker_name").html(obj.data["worker_name"]);
            $$("#worker_num").html(obj.data["worker_num"]);
            sessionStorage.setItem("workName", worker_name);
            sessionStorage.setItem("workNum", worker_num);
            sessionStorage.setItem("job", position);
            sessionStorage.setItem("idcard", idcard);
            sessionStorage.setItem("phone", contact_info);
            sessionStorage.setItem("depart", department);
            sessionStorage.setItem("homeaddress", address);
        });

        //退出按钮
        $$('.confirm-ok').on('click', function () {
            myApp.confirm('确定退出?', function () {
                clearInterval(MyMar);
                localStorage.removeItem("sessionid");
                //清空其他页面输入框数据
                mainView.router.back({
                    url: 'activateView.html',
                    force: true,
                    ignoreCache: true,
                });

            });
        });
    }

    if (page.name === 'password'){  
        $("#update-pwd").unbind("click"); 
        $("#update-pwd").css("color", "#7ac2d1"); 
        $$("#oldpwd").on('input', function(){         //API需要的参数 
            var session_id = localStorage.getItem('sessionid');
            var oldpwd = $$("#oldpwd").val(); 
            var newpwd = $$("#newpwd").val(); 
            var confirmpwd = $$("#confirmpwd").val();  
            if (oldpwd === "" || newpwd === "" || confirmpwd === ""){ 
                $("#update-pwd").unbind("click"); 
                $("#update-pwd").css("color", "#7ac2d1"); 
            } 
            else{ 
                $("#update-pwd").css("color", "white"); 
                $("#update-pwd").unbind("click");  
                $("#update-pwd").bind("click", function(){ 
                    //执行更改密码操作 
                    // 执行ajax请求 
                    ajaxget(session_id,oldpwd,newpwd);
                });  
            } 
        }); 
        $$("#newpwd").on('input', function(){ 
            //API需要的参数 
            var session_id = localStorage.getItem('sessionid');
            var oldpwd = $$("#oldpwd").val(); 
            var newpwd = $$("#newpwd").val(); 
            var confirmpwd = $$("#confirmpwd").val();  
            if (oldpwd === "" || newpwd === "" || confirmpwd === ""){ 
                $("#update-pwd").unbind("click"); 
                $("#update-pwd").css("color", "#7ac2d1"); 
            } 
            else{ 
                $("#update-pwd").css("color", "white"); 
                $("#update-pwd").unbind("click");  
                $("#update-pwd").bind("click", function() {
                    //执行更改密码操作 
                    // 执行ajax请求 
                    ajaxget(session_id,oldpwd,newpwd);
                });
            } 
        });  
        $$("#confirmpwd").on('input', function(){ 
            //API需要的参数 
            var session_id = localStorage.getItem('sessionid');
            var oldpwd = $$("#oldpwd").val(); 
            var newpwd = $$("#newpwd").val(); 
            var confirmpwd = $$("#confirmpwd").val();  
            if (oldpwd === "" || newpwd === "" || confirmpwd === ""){ 
                $("#update-pwd").unbind("click"); 
                $("#update-pwd").css("color", "#7ac2d1"); 
            } 
            else{ 
                $("#update-pwd").css("color", "white"); 
                $("#update-pwd").unbind("click");  
                $("#update-pwd").bind("click", function(){ 
                    //执行更改密码操作 
                    // 执行ajax请求 
                    ajaxget(session_id,oldpwd,newpwd);
                });  
            } 
        });
     }

});




